package com.design.pattern.state.common;

import com.design.pattern.state.domain.ChatRoom;
import com.design.pattern.state.domain.User;

/**
 * 用户房间权限处理
 */
public final class RoomAuthStatusHandlerUtils {
    /**
     * 获取用户进入房间房间的工具类
     *
     * @param room 房间
     * @param user 用户
     * @return
     */
    public static RoomAuth getStatus(ChatRoom room, User user) {
        if (room.getVip()) {
            //房间是VIP房间
            if (!user.getVip()) {
                //用户不是VIP用户,禁止访问房间
                return RoomAuth.LIMIT;
            }
            if (room.getHasPassword()) {
                //房间有密码,输入密码
                return RoomAuth.INSERT_PASSWORD;
            }

            //允许用户直接访问
            return RoomAuth.ALLOW;

        } else {
            //房间不是VIP房间
            if (room.getHasPassword()) {
                //房间有密码,输入密码
                return RoomAuth.INSERT_PASSWORD;
            }
            //允许进入房间
            return RoomAuth.ALLOW;


        }
    }
}
